package service

import (
	"context"

	biz "Cosmos.Communication/internal/biz"
)

type Ability interface {
	biz.DataSet
	biz.Invoke
	biz.Notify
	biz.Health
}

func NewAbility(d biz.DataSet, i biz.Invoke, n biz.Notify, h biz.Health) (a Ability, cf func(), ex error) {
	ability := &ability{
		d,
		i,
		n,
		h,
	}
	a = ability
	cf = ability.Close
	ex = nil
	return
}

type ability struct {
	idataset biz.DataSet
	iinvoke  biz.Invoke
	inotify  biz.Notify
	ihealth  biz.Health
}

func (a *ability) Close() {
	a.idataset.Close()
}

func (a *ability) Query(ctx context.Context, request *biz.DataQueryRequest) (result *biz.Result[*biz.DataQueryResponse], err error) {
	result, err = a.idataset.Query(ctx, request)
	return
}
func (a *ability) Subscribe(ctx context.Context, request *biz.DataSubscribeRequest) (result *biz.Result[*biz.DataSubscribeResponse], err error) {
	result, err = a.idataset.Subscribe(ctx, request)
	return
}
func (a *ability) Unsubscribe(ctx context.Context, request *biz.DataUnsubscribeRequest) (result *biz.Result[*biz.DataUnsubscribeResponse], err error) {
	result, err = a.idataset.Unsubscribe(ctx, request)
	return
}
func (a *ability) Push(ctx context.Context, data *biz.DataFrame) (err error) {
	err = a.idataset.Push(ctx, data)
	return
}

func (a *ability) Poll() *biz.DataFrame {
	return a.idataset.Poll()
}

func (a *ability) Invoke(ctx context.Context, request *biz.InvokeRequest) (result *biz.Result[*biz.InvokeResponse], err error) {
	result, err = a.iinvoke.Invoke(ctx, request)
	return
}

func (a *ability) Notify(ctx context.Context, request *biz.NotifyRequest) (result *biz.Result[*biz.NotifyResponse], err error) {
	result, err = a.inotify.Notify(ctx, request)
	return
}

func (a *ability) Check(ctx context.Context, request *biz.HealthCheckRequest) (result *biz.Result[*biz.HealthCheckResponse], err error) {
	result, err = a.ihealth.Check(ctx, request)
	return
}
